USE [Publicate]
GO

/****** Object:  Table [dbo].[Direcciones]    Script Date: 11/04/2012 22:31:34 ******/
SET ANSI_NULLS ON
GO

SET QUOTED_IDENTIFIER ON
GO

SET ANSI_PADDING ON
GO

CREATE TABLE [dbo].[Direcciones](
	[Id_Direccion] [int] IDENTITY(1,1) NOT NULL,
	[Direccion] [varchar](200) NOT NULL,
	[Id_Sector] [int] NOT NULL,
	[Latitud] [numeric](10, 10) NULL,
	[Longitud] [numeric](10, 10) NULL,
 CONSTRAINT [PK_Direcciones] PRIMARY KEY CLUSTERED 
(
	[Id_Direccion] ASC
)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]
) ON [PRIMARY]

GO

SET ANSI_PADDING OFF
GO

USE [Publicate]
GO

/****** Object:  Table [dbo].[Municipios]    Script Date: 11/04/2012 22:31:44 ******/
SET ANSI_NULLS ON
GO

SET QUOTED_IDENTIFIER ON
GO

SET ANSI_PADDING ON
GO

CREATE TABLE [dbo].[Municipios](
	[Id_Municipios] [int] IDENTITY(1,1) NOT NULL,
	[Nombre] [varchar](50) NOT NULL,
	[Id_Provincia] [int] NOT NULL,
 CONSTRAINT [PK_Municipios] PRIMARY KEY CLUSTERED 
(
	[Id_Municipios] ASC
)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]
) ON [PRIMARY]

GO

SET ANSI_PADDING OFF
GO

USE [Publicate]
GO

/****** Object:  Table [dbo].[Provincias]    Script Date: 11/04/2012 22:31:51 ******/
SET ANSI_NULLS ON
GO

SET QUOTED_IDENTIFIER ON
GO

SET ANSI_PADDING ON
GO

CREATE TABLE [dbo].[Provincias](
	[Id_Provincias] [int] IDENTITY(1,1) NOT NULL,
	[Nombre] [varchar](50) NOT NULL,
 CONSTRAINT [PK_Provincias] PRIMARY KEY CLUSTERED 
(
	[Id_Provincias] ASC
)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]
) ON [PRIMARY]

GO

SET ANSI_PADDING OFF
GO

USE [Publicate]
GO

/****** Object:  Table [dbo].[Sectores]    Script Date: 11/04/2012 22:32:00 ******/
SET ANSI_NULLS ON
GO

SET QUOTED_IDENTIFIER ON
GO

SET ANSI_PADDING ON
GO

CREATE TABLE [dbo].[Sectores](
	[Id_Sector] [int] IDENTITY(1,1) NOT NULL,
	[Nombre] [varchar](50) NOT NULL,
	[Id_Municipio] [int] NOT NULL,
 CONSTRAINT [PK_Sectores] PRIMARY KEY CLUSTERED 
(
	[Id_Sector] ASC
)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]
) ON [PRIMARY]

GO

SET ANSI_PADDING OFF
GO

USE [Publicate]
GO

/****** Object:  StoredProcedure [dbo].[ProcGuardarContatos]    Script Date: 11/04/2012 22:36:04 ******/
SET ANSI_NULLS ON
GO

SET QUOTED_IDENTIFIER ON
GO

-- =============================================
-- Author: <Author,,Name>
-- Create date: <Create Date,,>
-- Description: <Description,,>
-- =============================================
Create PROCEDURE [dbo].[ProcGuardarContatos]
@nombre as varchar(100),
@direccion as varchar(200)=null,
@telefono as varchar(20)=null,
@celular as varchar(20)=null,
@fax as varchar(20)=null,
@email as varchar(50)=null,
@company as varchar(80)=null,
@Id_Arrendedor as integer
AS
BEGIN
-- SET NOCOUNT ON added to prevent extra result sets from
-- interfering with SELECT statements.
SET NOCOUNT OFF;

insert into Contatos(Nombre, Direccion, Telefono, Celular, Fax, Email, Company, Id_Arrendador) values (@nombre,@direccion,@telefono,@celular,@fax,@email,@company,@Id_Arrendedor);
END

GO


USE [Publicate]
GO

/****** Object:  StoredProcedure [dbo].[ProcGetArrendedorById]    Script Date: 11/04/2012 22:37:04 ******/
SET ANSI_NULLS ON
GO

SET QUOTED_IDENTIFIER ON
GO

-- =============================================
-- Author:		<Author,,Name>
-- Create date: <Create Date,,>
-- Description:	<Description,,>
-- =============================================
create PROCEDURE [dbo].[ProcGetArrendedorById]
	-- Add the parameters for the stored procedure here
@ArrendedorID AS varchar(20)
AS
BEGIN
	-- SET NOCOUNT ON added to prevent extra result sets from
	-- interfering with SELECT statements.
	SET NOCOUNT OFF;

    -- Insert statements for procedure here
	select * from Arrendedores where 
	ArrendedorId=@ArrendedorID;
END

GO

USE [Publicate]
GO

/****** Object:  StoredProcedure [dbo].[ProcgGetContatoByIdArrendedor]    Script Date: 11/04/2012 22:37:15 ******/
SET ANSI_NULLS ON
GO

SET QUOTED_IDENTIFIER ON
GO

-- =============================================
-- Author:		<Author,,Name>
-- Create date: <Create Date,,>
-- Description:	<Description,,>
-- =============================================
CREATE PROCEDURE [dbo].[ProcgGetContatoByIdArrendedor]
	
	@ArrendedorId as integer
AS
BEGIN
	-- SET NOCOUNT ON added to prevent extra result sets from
	-- interfering with SELECT statements.
	SET NOCOUNT OFF;
Select * from Contatos
where Id_Arrendador=@ArrendedorId;
   
END

GO

ALTER TABLE [dbo].[Propiedades] 
DROP COLUMN [Id_Caracteristica_Producto] 
GO
ALTER TABLE [dbo].[Propiedades] 
ADD [ID_Direccion] [int] NULL
GO

